<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>网络流简介</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: 'Arial', sans-serif;
    }
    body {
      background-color: #F8FAFC;
      color: #1E293B;
      line-height: 1.6;
      overflow-x: hidden;
    }
    .container {
      max-width: 1200px;
      margin: 0 auto;
      padding: 0 20px;
    }
    h1, h2, h3 {
      color: #1E293B;
      margin-bottom: 1rem;
    }
    p {
      margin-bottom: 1.5rem;
    }
    section {
      padding: 4rem 0;
      border-bottom: 1px solid #E2E8F0;
      opacity: 0;
      transition: opacity 0.8s ease;
    }
    /* 交互元素 */
    .interactive-element {
      transition: all 0.3s ease;
    }
    .interactive-element:hover {
      transform: translateY(-5px);
    }
    /* 网络流可视化 */
    .flow-container {
      position: relative;
      width: 800px;
      height: 400px;
      margin: 40px auto;
    }
    .node {
      position: absolute;
      width: 50px;
      height: 50px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #ffffff;
      background-color: #00b0f0;
      font-weight: bold;
      z-index: 10;
      font-size: 20px;
      box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    }
    .source {
      background: #3B82F6;
    }
    .sink {
      background: #F59E0B;
    }
    .edges {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
      width: 100%;
      height: 100%;
    }
    .edge {
      stroke: #6B7280;
      stroke-width: 3;
      fill: none;
    }
    .edge-arrow {
      fill: #6B7280;
    }
    .flow-path {
      stroke: #F59E0B;
      stroke-width: 4;
      fill: none;
      stroke-dasharray: 1000;
      stroke-dashoffset: 1000;
      opacity: 0;
      transition: opacity 0.3s ease;
    }
    .flow-text {
      font-size: 14px;
      fill: #EF4444;
      font-weight: bold;
      opacity: 0;
      transition: opacity 0.5s ease;
    }

    /*响应式*/
    @media (max-width: 768px) {
      section {
        padding: 3rem 0;
      }
      .flow-container {
        width: 100%;
        height: 300px;
      }
      .node {
        width: 40px;
        height: 40px;
        font-size: 0.8rem;
      }
    }
  </style>
</head>
<body>
<!-- 导航栏 -->
<nav style="background: #3B82F6; color: white; padding: 1rem 0; position: sticky; top: 0; z-index: 20;">
  <div class="container">
    <h1 style="margin: 0; font-size: 1.5rem;">网络流简介</h1>
  </div>
</nav>

<header style="background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%); color: white; padding: 2rem 0; text-align: center;">
  <div class="container">
    <h1 style="font-size: 3rem; margin-bottom: 1rem; margin-top: 2rem; color: white;">什么是网络流？</h1>
    <p style="font-size: 1.2rem; max-width: 800px; margin: 0 auto;">探索这个基础但强大的算法概念，理解它如何解决现实世界中的问题</p>
    <h1 style="margin: 0; margin-top : 3rem;  text-align: end; font-size: 1.5rem;">庄豪毅-202300202066</h1>
  </div>
</header>

<main>
  <!-- 基本概念 -->
  <section id="concept">
    <div class="container">
      <h2 style="font-size: 2.5rem;">网络流基本概念</h2>
      <p>网络流是图论中的一个重要概念，它模拟了物质在网络中的流动过程。想象一下城市之间的交通网络、计算机网络中的数据传输，或者供水系统中的水流，这些都是网络流的实际应用。</p>
      <div class="interactive-element" style="background: #EFF6FF; padding: 1.5rem; border-radius: 8px; margin: 2rem 0;">
        <h3>关键术语</h3>
        <ul style="list-style-type: none; padding: 0;">
          <li style="margin-bottom: 0.5rem;"><strong>网络</strong>：由节点(顶点)和连接它们的边组成的图</li>
          <li style="margin-bottom: 0.5rem;"><strong>源点</strong>：物质开始流动的节点</li>
          <li style="margin-bottom: 0.5rem;"><strong>汇点</strong>：物质最终到达的节点</li>
          <li style="margin-bottom: 0.5rem;"><strong>容量</strong>：每条边能够承载的最大流量</li>
          <li style="margin-bottom: 0.5rem;"><strong>流量</strong>：实际在边上流动的量</li>
        </ul>
      </div>
    </div>
  </section>

  <!-- 可视化示例 -->
  <section id="visualization">
    <div class="container">
      <h2 style="font-size: 2.5rem;">网络流可视化</h2>
      <p>下面是一个简单的网络流示例。点击"开始流动"按钮，观察从源点(s)到汇点(t)的流量如何通过网络。</p>

      <div class="flow-container">
        <div class="nodes">
          <div class="node source" style="left: 50px; top: 176px;">s</div>
          <div class="node" style="left: 275px; top: 98px;">1</div>
          <div class="node" style="left: 275px; top: 252px;">2</div>
          <div class="node sink" style="left: 501px; top: 176px;">t</div>
        </div>

        <svg class="edges" width="800" height="400">
          <!-- s - 1 -->
          <path class="edge" d="M 100 200 L 300 150" />
          <path id="flow-path-s-1" class="flow-path" d="M 100 200 L 300 150" />
          <polygon class="edge-arrow" points="300,150 290,145 290,155" />
          <text id="flow-text-s-1" class="flow-text" x="200" y="170">5/10</text>

          <!-- s - 2 -->
          <path class="edge" d="M 100 200 L 300 250" />
          <path id="flow-path-s-2" class="flow-path" d="M 100 200 L 300 250" />
          <polygon class="edge-arrow" points="300,250 290,245 290,255" />
          <text id="flow-text-s-2" class="flow-text" x="200" y="230">3/8</text>

          <!-- 1 - t -->
          <path class="edge" d="M 300 150 L 500 200" />
          <path id="flow-path-1-t" class="flow-path" d="M 300 150 L 500 200" />
          <polygon class="edge-arrow" points="500,200 490,195 490,205" />
          <text id="flow-text-1-t" class="flow-text" x="400" y="170">5/5</text>

          <!-- 2 - t -->
          <path class="edge" d="M 300 250 L 500 200" />
          <path id="flow-path-2-t" class="flow-path" d="M 300 250 L 500 200" />
          <polygon class="edge-arrow" points="500,200 490,205 490,195" />
          <text id="flow-text-2-t" class="flow-text" x="400" y="230">3/3</text>

          <!-- 1 - 2 -->
          <path class="edge" d="M 300 150 L 300 250" />
          <path id="flow-path-1-2" class="flow-path" d="M 300 150 L 300 250" />
          <polygon class="edge-arrow" points="300,250 295,240 305,240" />
          <text id="flow-text-1-2" class="flow-text" x="280" y="200">2/4</text>
        </svg>
      </div>

      <button id="start-flow" style="background: #3B82F6; color: white; border: none; padding: 1rem 2rem; border-radius: 8px; cursor: pointer; font-size: 1rem; transition: all 0.3s ease;">
        开始流动
      </button>
      <div id="flow-result" style="margin-top: 1rem; font-weight: bold;"></div>
    </div>
  </section>

  <!-- 网络流实际应用 -->
  <section id="applications">
    <div class="container">
      <h2 style="font-size: 2.5rem;">网络流的实际应用</h2>
      <p>网络流算法在现实世界中有广泛的应用，以下是一些常见的例子：</p>
      <div class="interactive-element" style="display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 2rem;">
        <div style="background: #F1F5F9; padding: 1.5rem; border-radius: 8px; flex: 1 1 calc(50% - 0.5rem); min-width: 300px;">
          <h3 style="color: #3B82F6;">运输网络优化</h3>
          <p>物流公司使用网络流算法来优化货物运输路线，最大化运输能力并最小化成本。</p>
        </div>
        <div style="background: #F1F5F9; padding: 1.5rem; border-radius: 8px; flex: 1 1 calc(50% - 0.5rem); min-width: 300px;">
          <h3 style="color: #10B981;">计算机网络</h3>
          <p>互联网服务提供商使用网络流算法来管理带宽分配和路由数据流量。</p>
        </div>
        <div style="background: #F1F5F9; padding: 1.5rem; border-radius: 8px; flex: 1 1 calc(50% - 0.5rem); min-width: 300px;">
          <h3 style="color: #F59E0B;">任务分配</h3>
          <p>人力资源部门可以使用网络流算法来最优分配员工到不同任务。</p>
        </div>
        <div style="background: #F1F5F9; padding: 1.5rem; border-radius: 8px; flex: 1 1 calc(50% - 0.5rem); min-width: 300px;">
          <h3 style="color: #8B5CF6;">图像处理</h3>
          <p>在图像分割中，网络流算法可以帮助识别图像中的不同对象。</p>
        </div>
      </div>
    </div>
  </section>

  <!-- 相关算法简介 -->
  <section id="algorithms">
    <div class="container">
      <h2 style="font-size: 2.5rem;">网络流算法简介</h2>
      <p>解决网络流问题的主要算法包括：</p>
      <div class="interactive-element" style="background: #EFF6FF; padding: 1.5rem; border-radius: 8px; margin: 2rem 0;">
        <h3>福特-富尔克森算法(Ford-Fulkerson)</h3>
        <p>这是解决最大流问题的经典算法，它通过寻找从源点到汇点的增广路径并沿着这些路径增加流量，直到找不到更多增广路径为止。</p>
        <h3 style="margin-top: 1.5rem;">埃德蒙兹-卡普算法(Edmonds-Karp)</h3>
        <p>这是福特-富尔克森算法的一种改进版本，它总是选择最短的增广路径(使用广度优先搜索)，保证了算法的时间复杂度为O(VE²)。</p>
        <h3 style="margin-top: 1.5rem;">迪尼奇算法(Dinic)</h3>
        <p>这是一种更高效的最大流算法，它通过构建层次图并在层次图上寻找多条增广路径，时间复杂度为O(V²E)。</p>
      </div>
    </div>
  </section>

  <!-- 问题 -->
  <section id="quiz">
    <div class="container">
      <h2 style="font-size: 2.5rem;">检验你的理解</h2>
      <p>回答以下问题，检验你对网络流概念的理解：</p>
      <div id="quiz-container" style="background: #F1F5F9; padding: 1.5rem; border-radius: 8px; margin: 2rem 0;">
        <div id="quiz-question" style="font-weight: bold; margin-bottom: 1rem;">什么是网络流中的"源点"？</div>
        <div id="quiz-options" style="margin-bottom: 1.5rem;">
          <label style="display: block; margin-bottom: 0.5rem;">
            <input type="radio" name="quiz-answer" value="A"> A. 物质最终到达的节点
          </label>
          <label style="display: block; margin-bottom: 0.5rem;">
            <input type="radio" name="quiz-answer" value="B"> B. 物质开始流动的节点
          </label>
          <label style="display: block; margin-bottom: 0.5rem;">
            <input type="radio" name="quiz-answer" value="C"> C. 网络中容量最大的节点
          </label>
          <label style="display: block; margin-bottom: 0.5rem;">
            <input type="radio" name="quiz-answer" value="D"> D. 网络中连接边最多的节点
          </label>
        </div>
        <button id="submit-answer" style="background: #3B82F6; color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 8px; cursor: pointer; transition: all 0.3s ease;">
          提交答案
        </button>
        <div id="quiz-result" style="margin-top: 1rem; font-weight: bold;"></div>
      </div>
    </div>
  </section>
</main>

<!-- 页脚 -->
<footer style="background: #1E293B; color: white; padding: 2rem 0; text-align: center;">
  <div class="container">
    <p>© 2025 网络流简介</p>
  </div>
</footer>

<script>
  document.addEventListener('DOMContentLoaded', function() {
    // 元素淡入动画（监听滚动）
    const sections = document.querySelectorAll('section');
    const observer = new IntersectionObserver((entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          entry.target.style.opacity = 1;
        }
      });
    }, { threshold: 0.1 });
    sections.forEach(section => observer.observe(section));

    const startFlowBtn = document.getElementById('start-flow');
    const flowResult = document.getElementById('flow-result');

    startFlowBtn.addEventListener('click', function() {
      // 重置
      flowResult.textContent = '';
      document.querySelectorAll('.flow-path').forEach(path => {
        path.style.opacity = '0';
        path.style.strokeDashoffset = '1000';
      });
      document.querySelectorAll('.flow-text').forEach(text => {
        text.style.opacity = '0';
      });

      // 按顺序显示流量和流动效果，模拟流动过程
      animateFlow('flow-path-s-1', 'flow-text-s-1', 500);
      animateFlow('flow-path-s-2', 'flow-text-s-2', 1000);
      animateFlow('flow-path-1-2', 'flow-text-1-2', 1500);
      animateFlow('flow-path-1-t', 'flow-text-1-t', 2000);
      animateFlow('flow-path-2-t', 'flow-text-2-t', 2000);

      // 显示结果
      setTimeout(() => {
        flowResult.textContent = '成功！流量已从源点(s)流向汇点(t)。';
        flowResult.style.color = '#10B981';
        startFlowBtn.textContent = '重新演示';
      }, 3000);
    });

    // 流动动画函数
    function animateFlow(pathId, textId, delay) {
      setTimeout(() => {
        const path = document.getElementById(pathId);
        const text = document.getElementById(textId);

        // 显示路径和文本
        path.style.opacity = '1';
        text.style.opacity = '1';

        // 计算路径长度
        const length = path.getTotalLength();

        // 设置动画
        path.style.transition = 'none';
        path.style.strokeDasharray = length + ' ' + length;
        path.style.strokeDashoffset = length;

        // 触发重绘
        path.getBoundingClientRect();

        // 应用动画
        path.style.transition = 'stroke-dashoffset 1.5s ease-in-out';
        path.style.strokeDashoffset = '0';
      }, delay);
    }

    const submitAnswerBtn = document.getElementById('submit-answer');
    const quizResult = document.getElementById('quiz-result');

    submitAnswerBtn.addEventListener('click', function() {
      const selectedAnswer = document.querySelector('input[name="quiz-answer"]:checked');
      if (!selectedAnswer) {
        quizResult.textContent = '请选择一个答案';
        quizResult.style.color = '#EF4444';
        return;
      }
      if (selectedAnswer.value === 'B') {
        quizResult.textContent = '正确！源点是物质开始流动的节点。';
        quizResult.style.color = '#10B981';
      } else {
        quizResult.textContent = '不正确。源点是物质开始流动的节点，而不是最终到达的节点。';
        quizResult.style.color = '#EF4444';
      }
    });

  });
</script>
</body>
</html>
